package com.ruoyi.central.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.ruoyi.cache.common.CacheConstants;
import lombok.extern.slf4j.Slf4j;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service;
import com.ruoyi.common.core.service.CustomServiceImpl;
import com.ruoyi.central.mapper.TopCentralControllerAlarmRecordMapper;
import com.ruoyi.central.domain.TopCentralControllerAlarmRecord;
import com.ruoyi.central.service.ITopCentralControllerAlarmRecordService;
import com.ruoyi.common.utils.StringUtils;

/**
 * 报警记录Service业务层处理
 *
 * @author ruoyi
 * @date 2022-02-25
 */
@Service
@Slf4j
@CacheConfig(cacheNames = CacheConstants.EhcacheName.CONTINUAL_CACHE_NAME)
public class TopCentralControllerAlarmRecordServiceImpl extends CustomServiceImpl<TopCentralControllerAlarmRecordMapper,TopCentralControllerAlarmRecord> implements ITopCentralControllerAlarmRecordService
{
    /**
     * 查询报警记录
     * 注意：只操作未被标记为删除的数据！
     * @param id 报警记录主键
     * @param columns 查询指定的列
     * @return 报警记录
     */
    @Override
    public TopCentralControllerAlarmRecord selectById(Integer id, SFunction<TopCentralControllerAlarmRecord,?> ... columns){

        if(StringUtils.isNotEmpty(columns)){
            return selectOne(lambdaQuery().select(columns).eq(TopCentralControllerAlarmRecord::getId,id));
        }
        return super.selectById(id);
    }

    /**
     * 查询报警记录列表
     *
     * @param topCentralControllerAlarmRecord 报警记录
     * @return 报警记录
     */
    @Override
    public List<TopCentralControllerAlarmRecord> selectList(TopCentralControllerAlarmRecord topCentralControllerAlarmRecord)
    {
        return getBaseMapper().selectTopCentralControllerAlarmRecordList(topCentralControllerAlarmRecord);
    }

    /**
     * 获取所有的报警记录数据
     * 注意：只操作未被标记为删除的数据！
     * @return Map<Integer,TopCentralControllerAlarmRecord> 集合
     */
    @Cacheable
    @Override
    public Map<Integer,TopCentralControllerAlarmRecord> selectAllMap(){

        return getBaseMapper().selectList(customLambdaQuery().select(TopCentralControllerAlarmRecord::getId))
                .stream().collect(Collectors.toMap(TopCentralControllerAlarmRecord::getId,v->v));
    }

    /**
     * 新增报警记录
     *
     * @param topCentralControllerAlarmRecord 报警记录
     * @return 结果
     */
    @CacheEvict(keyGenerator=CacheConstants.KeyGeneratorName.EHCACHE_KEY_GENERATOR_EVICT)
    @Override
    public boolean insert(TopCentralControllerAlarmRecord topCentralControllerAlarmRecord)
    {
        return super.insert(topCentralControllerAlarmRecord);
    }

    /**
     * 新增（批量）报警记录
     *
     * @param topCentralControllerAlarmRecordList 实体对象集合
     */
    @CacheEvict(keyGenerator=CacheConstants.KeyGeneratorName.EHCACHE_KEY_GENERATOR_EVICT)
    @Override
    public boolean insertBatch(Collection<TopCentralControllerAlarmRecord> topCentralControllerAlarmRecordList, int batchSize) {
        return super.insertBatch(topCentralControllerAlarmRecordList, batchSize);
    }

    /**
     * 删除 报警记录 根据编号
     * @param id
     * @return true 删除成功 false 删除失败
     */
    @CacheEvict(keyGenerator=CacheConstants.KeyGeneratorName.EHCACHE_KEY_GENERATOR_EVICT)
    @Override
    public boolean deleteById(Serializable id) {
        return super.deleteById(id);
    }

    /**
     * 批量删除 报警记录 根据 编号集合
     * @param ids
     * @return true 删除成功 false 删除失败
     */
    @CacheEvict(keyGenerator=CacheConstants.KeyGeneratorName.EHCACHE_KEY_GENERATOR_EVICT)
    @Override
    public boolean deleteByIds(Collection<? extends Serializable> ids) {
        return super.deleteByIds(ids);
    }

    /**
     * 批量修改 报警记录 根据唯一编号
     * @param topCentralControllerAlarmRecordList
     * @param batchSize  更新批次数量
     * @return true 修改成功 false 修改失败
     */
    @CacheEvict(keyGenerator=CacheConstants.KeyGeneratorName.EHCACHE_KEY_GENERATOR_EVICT)
    @Override
    public boolean updateBatchById(Collection<TopCentralControllerAlarmRecord> topCentralControllerAlarmRecordList, int batchSize) {
        return super.updateBatchById(topCentralControllerAlarmRecordList, batchSize);
    }

    /**
     * 修改 报警记录
     * @param  topCentralControllerAlarmRecord
     * @param updateWrapper
     * @return
     */
    @CacheEvict(keyGenerator=CacheConstants.KeyGeneratorName.EHCACHE_KEY_GENERATOR_EVICT)
    @Override
    public boolean update(TopCentralControllerAlarmRecord topCentralControllerAlarmRecord, LambdaUpdateWrapper<TopCentralControllerAlarmRecord> updateWrapper) {
        return super.update(topCentralControllerAlarmRecord,updateWrapper);
    }

    /**
     * 修改报警记录
     *注意：只操作未被标记为删除的数据！
     * @param topCentralControllerAlarmRecord 报警记录
     * @return 结果
     */
    @CacheEvict(keyGenerator=CacheConstants.KeyGeneratorName.EHCACHE_KEY_GENERATOR_EVICT)
    @Override
    public boolean updateById(TopCentralControllerAlarmRecord topCentralControllerAlarmRecord)
    {
        return super.updateById(topCentralControllerAlarmRecord);
    }


}
